<template>
  <div class="NewDiscShelves">
    <div class="h3-title">
      <div class="left">
        <span class="font-icon"></span>
        <b class="title">新碟上架</b>
      </div>
      <div class="right">
        <span class="more-text" @click="screenSongList('全部风格')">更多</span>
        <span class="iconfont">&#xe6d7;</span>
      </div>
    </div>
    <div class="swiper-box">
      <div class="swiper">
        <el-carousel
          height="180px"
          ref="slider"
          trigger="click"
          indicator-position="none"
          :autoplay="false"
        >
          <el-carousel-item>
            <div class="list-box">
              <div class="list" v-for="item in playlists1" :key="item.id">
                <div class="img">
                  <img
                    @click="albumInfo(item)"
                    :src="item.coverImgUrl"
                    alt=""
                  />
                  <i @click="albumPlay(item)" class="iconfont iconfont-cursor"
                    >&#xe638;</i
                  >
                </div>
                <div class="details">
                  <p class="title" @click="albumInfo(item)">
                    {{ item.name }}
                  </p>
                  <p class="auth" @click="albumAuthInfo(item.userId)">
                    {{ item.creator.nickname }}
                  </p>
                </div>
              </div>
            </div>
          </el-carousel-item>
          <el-carousel-item>
            <div class="list-box">
              <div class="list" v-for="item in playlists2" :key="item.id">
                <div class="img">
                  <img
                    @click="albumInfo(item)"
                    :src="item.coverImgUrl"
                    alt=""
                  />
                  <i @click="albumPlay(item)" class="iconfont iconfont-cursor"
                    >&#xe638;</i
                  >
                </div>
                <div class="details">
                  <p class="title" @click="albumInfo(item)">
                    {{ item.name }}
                  </p>
                  <p class="auth" @click="albumAuthInfo(item.userId)">
                    {{ item.creator.nickname }}
                  </p>
                </div>
              </div>
            </div>
          </el-carousel-item>
        </el-carousel>
        <span @click="slideNext" class="iconfont left-button">&#xe642;</span>
        <span @click="slide" class="iconfont right-button">&#xe61d;</span>
      </div>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex"
import { topPlaylist } from "@/api";
export default {
  name: "NewDiscShelves",
  data() {
    return {
      options: {
        loop: true, //循环滚动
        pagination: false,
        slidesToScroll: 1,
        infinite: 4,
        speed: 600,
        currentPage: 0,
      },
      playlists: [],
      playlists1: [],
      playlists2: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    ...mapActions("music",["ALBUM_MUSIC_LIST_FORMAT","SET_CHANGE_MUSIC_URL"]),
    init() {
      this.getTopPlaylist();
    },
    getTopPlaylist() {
      topPlaylist({ order: "new", limit: 10 }).then((data) => {
        this.playlists1 = data.playlists.slice(0, 5);
        this.playlists2 = data.playlists.slice(5);
        this.playlists = data.playlists;
      });
    },
    screenSongList(val) {
      this.$router.push({
        name: "findMusicNewDisc",
        query: {
          msg: val,
        },
      });
    },
    slideNext() {
      this.$refs.slider.prev()
      // this.$refs.slider.$emit("slideNext");
    },
    slide() {
      this.$refs.slider.next()

      // this.$refs.slider.$emit("slidePre");
    },
    albumAuthInfo(val) {
      console.log(val, "歌手详情");
      if (!val) {
        this.$Notification("此用户暂无信息");
        return;
      }
      this.$router.push({
        name: "userpage",
        query: {
          id: val,
        },
      });
    },
    albumInfo(val) {
      this.$router.push({
        name: "albumDetails",
        query: {
          id: val.id,
        },
      });
    },
    async albumPlay(val) {
      let { config, musicFlag } = await this.ALBUM_MUSIC_LIST_FORMAT(val);
      if (musicFlag) {
        config.map(async (item) => {
          await this.SET_CHANGE_MUSIC_URL(item);
        });
        this.$Notification("添加成功!", "success");
      } else {
        this.$Notification("此歌曲暂无版权。");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.NewDiscShelves {
  padding: 10px 20px;
  ::v-deep .el-carousel__item {
    display: flex;
    align-items: center;
  }
  .list-box {
    font-size: 12px;
    padding: 0 10px;
    color: #333;
    text-align: left;
    display: flex;
    width: 100%;
    justify-content: space-around;
    .list {
      .details {
        .title {
          margin-top: 4px;
          color: #000;
          cursor: pointer;
          &:hover {
            text-decoration: underline;
          }
        }
        .auth {
          cursor: pointer;
          &:hover {
            text-decoration: underline;
          }
          color: rgb(102, 102, 102);
          width: 100px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .img {
        cursor: pointer;
        width: 100px;
        height: 100px;
        position: relative;
        &:hover {
          .iconfont-cursor {
            display: block;
          }
        }
        .iconfont-cursor {
          &:hover {
            color: #ddd;
          }
          display: none;
          position: absolute;
          width: 20px;
          height: 20px;
          right: 10px;
          bottom: 15px;
          font-size: 20px;
          cursor: pointer;
          color: #efefef;
        }
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .swiper-box {
    margin-top: 20px;
    height: 180px;
    border: 1px solid rgb(211, 211, 211);
    .swiper {
      height: 100%;
      position: relative;
      .left-button {
        z-index: 5;
        cursor: pointer;
        position: absolute;
        left: 2px;
        top: 70px;
        height: 30px;
        width: 30px;
        font-weight: 600;
        user-select: none;
      }
      .right-button {
        user-select: none;
        z-index: 5;
        cursor: pointer;
        position: absolute;
        right: -10px;
        top: 70px;
        height: 30px;
        width: 30px;
        font-weight: 600;
      }
      width: 704px;
      height: 100%;
      box-sizing: border-box;
      border: 1px solid rgb(255, 255, 255);
      background-color: rgb(245, 245, 245);
    }
  }
}
.h3-title {
  display: flex;
  padding-bottom: 4px;
  justify-content: space-between;
  border-bottom: 2px solid rgb(193, 13, 12);
  .right {
    .more-text {
      font-size: 12px;
      color: #666;
      cursor: pointer;
      &:hover {
        text-decoration: underline;
      }
    }
    .iconfont {
      margin: 0 6px;
      color: rgb(193, 13, 12);
      font-size: 12px;
    }
  }
  .left {
    display: flex;
    align-items: center;
    i {
      margin: 0 13px;
      height: 11px;
      border-right: 2px solid #ccc;
    }
    .text {
      font-size: 12px;
      color: #666;
      cursor: pointer;
      &:hover {
        text-decoration: underline;
      }
    }
    .title {
      cursor: pointer;
      margin-right: 20px;
      font-size: 20px;
      font-weight: normal;
      line-height: 28px;
    }
    .font-icon {
      margin: 0 10px;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background-color: rgb(193, 13, 12);
      position: relative;
      &::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        margin: auto;
        background-color: #fff;
        width: 5px;
        height: 5px;
        border-radius: 50%;
        transform: translate(-0px, -0.5px);
      }
    }
  }
}
</style>